package com.boot.database.service;

import com.boot.core.thread.ThreadLocalHelper;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description 本地用户存储，用于表属性create_user与update_user
 * @date 2019/11/14 14:11
 **/
public class UserHolder implements CurrentUserHandler {

    private static final String KEY = CurrentUserHandler.class.getName();

    @Override
    public void setUsername(String username) {
        ThreadLocalHelper.setValue(KEY, username);
    }

    @Override
    public String getUsername() {
        String username = (String) ThreadLocalHelper.getValue(KEY);
        if (username == null || username.isEmpty()) {
            return "system";
        } else {
            return username;
        }
    }

}
